/*
 * Created on Oct 4, 2003
 *
 * Mihai Postelnicu
 * 
 */
package ro.gateway.aida.stats;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

import org.jfree.data.DefaultCategoryDataset;

import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;



public class SectorLineChart implements DatasetProducer, Serializable {

	// These values would normally not be hard coded but produced by    
	// some kind of data source like a database or a file    

	private final String[] categories =
		{ "mon", "tue", "wen", "thu", "fri", "sat", "sun" };
		
	private final String[] seriesNames =
		{
			"cewolfset.jsp",
			"tutorial.jsp",
			"testpage.jsp",
			"performancetest.jsp" };
			
	private final Integer[][] values =
		new Integer[seriesNames.length][categories.length];
		
	public Object produceDataset(Map params) throws DatasetProduceException {
		
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		for (int series = 0; series < seriesNames.length; series++) {
			int lastY = (int) (Math.random() * 1000 + 1000);
			for (int i = 0; i < categories.length; i++) {
				final int y = lastY + (int) (Math.random() * 200 - 100);
				lastY = y;
				dataset.addValue(
					(double) y,
					seriesNames[series],
					categories[i]);
			}
		}
		return dataset;
	}
	
	public boolean hasExpired(Map params, Date since) {
		
		return (System.currentTimeMillis() - since.getTime()) > 5000;
	}
	
	public String getProducerId() {
		return "PageViewCountData DatasetProducer";
	}
}